import {useEffect, useState} from 'react'
import {useLocation, useNavigate, Outlet} from 'react-router-dom'
import PullRefreshList from '../../components/pullRefreshList/index.jsx'
import request from '../../utils/request.jsx'

const Commodity= () => {
    const navigate = useNavigate();
    const location = useLocation();
    let {pathname} = location
    let path = pathname.split('/')[pathname.split('/').length-1]
    const [data, setData] = useState([])
    useEffect(() => {
        getDate()
    }, [path])

    const getDate = async() => {
        let {data} = await request.get(`/productDetails?productId=${path}`)
        setData(data)
    }
    const onPullRefresh = item => {
        navigate(`${pathname}/product/${item}`)
    }
    return (
        <div>
            <PullRefreshList data={data} click={onPullRefresh}/>
            <Outlet />
        </div>
    )
}

export default Commodity;